package school.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DatabaseManager {

		private SqlSessionFactory factory;
		private static DatabaseManager instance;
		private DatabaseManager() {
			InputStream in = null;
			try{
				in = Resources.getResourceAsStream("school/dao/config/school-config.xml");
			}catch(IOException e) {
				e.printStackTrace();
			}
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			factory = builder.build(in);
		}
		
		public static DatabaseManager getInstance() {
			if(instance==null) {
				instance = new DatabaseManager();
			}
			return instance;
		}
		
		public SqlSessionFactory getSqlSessionFactory() {
			return factory;
		}
}
